'''
@author: haiwen
@date: 2020/9/25
@file: business.py
'''
#实现具体的业务类API

#部门API类
from pylib.webapi.common import BaseAPI

#部门
class OrganizAPI(BaseAPI):
    def __init__(self,cookies=None):
        super().__init__(cookies)
        #设置默认ID
        self.parent_id=self.get_top_organiz()

    def del_all(self):
        objs = self.list_all()[1:]
        for obj in objs:
            self.delete(obj['_id'])

    def add(self,**kw):
        #判断用户是否传递parent参数
        if not kw.get('parent'):
            kw['parent']=self.parent_id  #替换默认parentid
        return super().add(**kw)  #调用父类的add方法返回相关数据

    def edit(self,_id,**kw):
        # 判断用户是否传递parent参数
        if not kw.get('parent'):
            kw['parent'] = self.parent_id  # 替换默认parentid
        return super().edit(_id,**kw)  # 调用父类的add方法返回相关数据

    #获取总公司的ID
    def get_top_organiz(self):
        parent=self.list_all()[0]
        return parent['_id']

#合同
class ContractsAPI(BaseAPI):
    pass

#签约对象
class AccountsAPI(BaseAPI):
    pass

#合同分类
class ContractTypesAPI(BaseAPI):
    pass